package com.cuitrip.util.track;

import com.cuitrip.app.MainApplication;
import com.cuitrip.storage.prefrence.SettingPreferences;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
import com.lab.logtrack.AppLog;
import com.lab.utils.ToastUtil;

/**
 * Created by ak on 16/1/11.
 */
public class TrackUtil {

    public static final String TAG = "track:";

    public static boolean isShowToast = false;

    public static void setShowToast(boolean isShowToast){
        SettingPreferences.getInstance().putBoolean(SettingPreferences.DebugKeys.KEY_TRACK_TOAST, isShowToast);
        TrackUtil.isShowToast = isShowToast;
    }

    public static void trackScreenName(String name){
        AppLog.d(TAG, "Setting screen name: " + name);
        if (isShowToast){
            ToastUtil.toast(TAG + name);
        }
        Tracker mTracker = MainApplication.getInstance().getDefaultTracker();
        mTracker.setScreenName(name);
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
    }


    public static void trackScreenName(String name, Object...parameters){
        AppLog.d(TAG, "Setting screen name: " + name);
        String screenName = String.format(name, parameters);
        if (isShowToast){
            ToastUtil.toast(TAG + screenName);
        }
        Tracker mTracker = MainApplication.getInstance().getDefaultTracker();
        mTracker.setScreenName(screenName);
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
    }

}
